package com.twohand.admin.Controller;

import com.twohand.admin.Annotation.Permission;
import com.twohand.admin.Dto.*;
import com.twohand.admin.Entity.Bill;
import com.twohand.admin.Entity.Order;
import com.twohand.admin.Service.BillService;
import com.twohand.admin.Service.OrderService;
import com.twohand.admin.Util.PageResponse;
import com.twohand.admin.Vo.BillDetailOption;
import com.twohand.admin.Vo.BillDetailVo;
import com.twohand.admin.Vo.Order.OrderStatisVo;
import com.twohand.admin.Vo.SelectOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/bill")
public class BillController {
    @Autowired
    BillService billService;
    @Permission(value = "bill:list")
    @GetMapping
    PageResponse<Bill> getBillList(BillListQueryDto billListQueryDto){
        return billService.billList(billListQueryDto);
    }
    @Permission(value = "bill:add")
    @PostMapping
    Object addBill(@RequestBody Bill bill){
        return billService.addBill(bill);
    }
    @Permission(value = "bill:edit")
    @PutMapping
    Boolean changeBill(@RequestBody Bill bill){
        //该接口默认不修改支付状态
        bill.setStatus(null);
        return billService.changeBill(bill);
    }
    @Permission(value = "bill:updateAndStatus")
    @PutMapping("/updateAndStatus")
    Boolean updateBillAndStatus(@RequestBody Bill bill){
        return billService.changeBill(bill);
    }
    @Permission(value = "bill:delete")
    @DeleteMapping("/{id}")
    Boolean delBill(@PathVariable Integer id)
    {
        return  billService.delOBill(id);
    }
    @Permission(value = "bill:edit")
    @GetMapping("/detail")
    BillDetailVo getBillDetail(Integer id){
        return billService.getBillDetail(id);
    }
    @GetMapping("/detail/options")
    BillDetailOption getBillOption(){
        return billService.getBillOptions();
    }
    @PostMapping("/billCheck")
    Object checkBill(@RequestBody List<BillInfoDto> billInfos){
        return billService.checkAndAddBill(billInfos);
    }
    @GetMapping("/orderStatis")
    OrderStatisVo getOrderStatis(BillListQueryDto billListQueryDto){
        return billService.getOrderTotal(billListQueryDto);
    }
    @Permission("billbatch:delete")
    @PostMapping("/batchChangeStatus")
    Boolean batchChangeStatus(@RequestBody BatchChangeStatusDto batchChangeStatusDto){
        return billService.batchChangeStatus(batchChangeStatusDto);
    }
    @Permission("billbatch:changeShop")
    @PostMapping("/batchChangeShop")
    Map batchChangeShop(@RequestBody BatchChangeShopDto batchChangeShopDto){
        return billService.batchChangeShop(batchChangeShopDto);
    }
}
